[Week02] BOJ: 퇴사2 #20
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
문제 정보
풀이 방법
간단히 어떤 방식으로 풀었는지 설명해주세요.
체크리스트
{닉네임}.{확장자})추가 코멘트
(선택사항) 추가로 공유하고 싶은 내용이 있다면 작성해주세요.
#1
처음에는 dp[i][j]: i일에 상담을 한 경우(j==1) 또는 하지 않은 경우(j==0) 최대 수익으로 설정했습니다. 상담은 최대 50일까지 지속될 수 있으므로 매번 지난 50일의 상담을 확인하며 상담을 한 경우 최대 수익을 구했습니다. 위 로직은 50일 이전의 최대 수익을 제대로 반영하지 못합니다(1~50일 이전의 dp[x][1]만 체크하므로).
#2
최댓값 전파 문제는 해결했으나 위 로직은 수익 계산 시점으로 인한 불일치가 생깁니다. 1일차이 5일이 걸리고 수익이 100인 상담을 시작하면 dp[1][1]=100이 됩니다. 2일차가 되면 dp[2][0]은 dp[1][1]인 100을 가져오는데, 1일차 상담은 아직 끝나지 않았습니다. 2일차 상담을 시작하면 이미 1일차 상담의 수익을 가지고 시작합니다(1일차 상담을 진행한 경우 2일차 상담을 진행할 수도 없긴 함).
#3
dp[i]: i일 째 가능한 최대 수익
dp[i + 1] = max(dp[i + 1], dp[i]);: 상담 하지 않고 건너뛰는 경우오늘 상담하는 경우 미래의 수익을 갱신
시간복잡도: O(N)